from django.contrib.auth.models import Group
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser

from meiduo_admin.serializers.admin import AdminSerializer
from meiduo_admin.serializers.group import GroupSerializer
from meiduo_admin.utils import PageNum
from users.models import User


class AdminView(ModelViewSet):
    """管理员管理"""
    queryset = User.objects.all()
    pagination_class = PageNum
    permission_classes = [IsAdminUser]
    serializer_class = AdminSerializer

    def simple(self, request):
        """获取组"""
        # 1、查询分组表
        data=Group.objects.all()
        # 2、返回分组信息
        ser=GroupSerializer(data,many=True)
        return Response(ser.data)
